package com.atguigu.test.dacahngmainshitidierji.reference;

import java.lang.ref.WeakReference;

/**
 * 2 * @Author: madonghui
 * 3 * @Date: 2020/11/23 17:53
 * 4
 */
public class WeakReferenceDemo {
    //虚引用不管内存够不够用都会被回收
    public static void weakReference_method(){
        Object o = new Object();
        WeakReference<Object> objectWeakReference = new WeakReference<>(o);
        System.out.println(o);
        System.out.println(objectWeakReference.get());

        o = null;
        System.gc();

        System.out.println(o);
        System.out.println(objectWeakReference.get());
    }

    public static void main(String[] args) {
        weakReference_method();
    }
}
